package ai.people.platform.archives.controller;

import ai.people.netmon.framework.domain.archives.request.ClueListRequest;
import ai.people.netmon.framework.domain.archives.request.ClueShareRequest;
import ai.people.netmon.framework.domain.archives.request.ClueSharedRecordListRequest;
import ai.people.netmon.framework.domain.archives.vo.ClueListVO;
import ai.people.netmon.framework.domain.archives.vo.ClueSharedRecordListVO;
import ai.people.netmon.framework.domain.archives.vo.ShareUserVO;
import ai.people.netmon.framework.model.response.ListResponse;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.platform.archives.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 线索接口
 *
 * @author zhenglin
 * @date 2022/5/31
 */
@RestController
@RequestMapping("/clue")
public class ClueController {

    @Autowired
    ClueService clueService;

    /**
     * 线索列表(用户)
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link ClueListVO}>>
     */
    @PostMapping("/my/list")
    public Result<PageResponse<ClueListVO>> myClueList(@Validated @RequestBody ClueListRequest request) {
        PageResponse<ClueListVO> list = clueService.myClueList(request);
        return ResultUtil.success(list);
    }

    /**
     * 线索列表(管理员)
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link ClueListVO}>>
     */
    @PostMapping("/admin/list")
    public Result<PageResponse<ClueListVO>> adminClueList(@Validated @RequestBody ClueListRequest request) {
        PageResponse<ClueListVO> list = clueService.adminClueList(request);
        return ResultUtil.success(list);
    }

    /**
     * 新增线索
     *
     * @param archivesId 档案id
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping
    @PreAuthorize("hasAuthority('clue:manage')")
    public Result<Boolean> addClue(@RequestParam Long archivesId) {
        clueService.addClue(archivesId);
        return ResultUtil.success();
    }

    /**
     * 分享用户列表
     *
     * @param clueId 线索id
     * @return {@link Result}<{@link ListResponse}<{@link ShareUserVO}>>
     */
    @GetMapping("/listShareUsers")
    public Result<ListResponse<ShareUserVO>> listShareUsers(@NotNull(message = "线索id为空") @RequestParam("clueId") Long clueId){
        return ResultUtil.success(clueService.shareUserList(clueId));
    }

    /**
     * 分享线索
     *
     * @param request 协会
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/share")
    @PreAuthorize("hasAuthority('clue:manage')")
    public Result<Boolean> shareClue(@Validated @RequestBody ClueShareRequest request){
        clueService.shareClue(request);
        return ResultUtil.success();
    }

    /**
     * 分享线索检查(用户标签和线索标签是否一致)
     *
     * @param association 协会
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/share/check")
    @PreAuthorize("hasAuthority('clue:manage')")
    public Result<Boolean> shareClueCheck(@Validated @RequestBody ClueShareRequest association){
        boolean flag = clueService.shareClueCheck(association);
        return ResultUtil.success(flag);
    }

    /**
     * 线索动作记录列表
     *
     * @param request 请求
     * @return {@link Result}<{@link List}<{@link ClueSharedRecordListVO}>>
     */
    @PostMapping("/sharedRecord/list")
    @PreAuthorize("hasAuthority('clue:manage')")
    public Result<PageResponse<ClueSharedRecordListVO>> sharedRecord(@Validated @RequestBody ClueSharedRecordListRequest request) {
        PageResponse<ClueSharedRecordListVO> list = clueService.sharedRecord(request);
        return ResultUtil.success(list);
    }

}
